package com.swn.cm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swn.common.util.DbHelper;
import com.swn.common.util.PageListData;
import com.swn.common.util.StringUtil;

@Service
public class TestProjectService {
	
	@Autowired
	private DbHelper dbHelper;
	
	/**
	 * 查询项目列表
	 * 
	 * @param param
	 * @return List<Map<String,Object>>
	 * @throws Exception 
	 *
	 * @Author xx
	 * @Date xx
	 * @Note <这里是方法的备注>
	 * @company 济南舒卫能生物技术有限公司
	 */
	public List<Map<String, Object>> queryProjectList(PageListData pageListData,Map<String, Object> param) throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("select project_id, projectName, projectManager, projectType, projectImgUrl from test_project where 1=1");
		String projectName = (String) param.get("projectName");
		String projectManager = (String)param.get("projectManager");
		if(StringUtil.isNotEmpty(projectName)){
			sb.append(" and projectName like '%"+projectName+"%'"); 
		}
		if(StringUtil.isNotEmpty(projectManager)){
			sb.append(" and projectManager like '%"+projectManager+"%'");
		}
		return dbHelper.queryPageMapList(pageListData, sb.toString(), param);
	}
	
	/**
	 * 添加
	 */
	public int addTestProject(Map<String, Object> param){
		
		return dbHelper.saveMap(param, "test_project");
		
	}
	
	/**
	 * 修改
	 */
	public int updateTestProject(Map<String, Object> param){
		return dbHelper.updateMap(param, "test_project");
	}
	
	/**
	 * 查询单条数据
	 */
	public Map<String, Object> queryProjectById(long project_id)throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("select project_id, projectName, projectManager,projectImgUrl,projectType from test_project where project_id = "+project_id);
		return dbHelper.queryForMap(sb.toString());
		
	}
	
	/**
	 * 删除一条记录
	 */
	public int deleteTestProject(long project_id){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("project_id", project_id);
		return dbHelper.delete(param, "test_project");
	}
	/**
	 * 查询项目类型
	 * @return
	 */
	public List<Map<String, Object>> queryProjectTypes(){
		StringBuilder sb = new StringBuilder();
		sb.append("select id, code as projectType_code, name as projectType_name from test_projectTypes");
		return dbHelper.queryForList(sb.toString(), null);
	}
	
	
}
